package com.nimitz.web.controller.module.bi;

import com.nimitz.common.core.controller.BaseController;
import com.nimitz.common.core.domain.AjaxResult;
import com.nimitz.common.utils.StringUtils;
import com.nimitz.module.bi.domain.BiEmployee;
import com.nimitz.module.bi.service.IBiEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 人员报表
 */
@RestController
@Api(tags = "人员报表")
@RequestMapping("/module/bi")
public class BiEmployeeController extends BaseController {
    @Resource
    private IBiEmployeeService employeeService;

    /**
     * 生成人员报表
     *
     * @param statistics 统计日期
     * @return 人员
     */
    @GetMapping("/generate/{statistics}")
    @ApiOperation(value = "根据统计日期生成人员报表")
    public AjaxResult generate(@PathVariable(value = "statistics", required = false) String statistics) {
        return toAjax(employeeService.generateEmployee(statistics));
    }

    /**
     * 根据部门id查询人员
     *
     * @param deptId 部门id
     * @return 人员
     */
    @GetMapping("/{deptId}")
    @ApiOperation(value = "根据部门id查询人员")
    public AjaxResult getInfo(@PathVariable(value = "deptId", required = false) Integer deptId) {
        AjaxResult ajax = AjaxResult.success();
        if (StringUtils.isNotNull(deptId)) {
            BiEmployee employee = employeeService.selectEmployeeByDeptId(deptId);
            ajax.put(AjaxResult.DATA_TAG, employee);
        }
        return ajax;
    }
}
